package com.hdu.controller.mediaManagement;


import com.hdu.entity.MediaFiles;
import com.hdu.exception.BizException;
import com.hdu.pojo.Result;
import com.hdu.service.IMediaFileService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文件打开实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2024-05-20
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "文件打开接口")
@RequestMapping("/open")
public class MediaOpenController {

    private final IMediaFileService mediaFileService;

    @GetMapping("/preview/{mediaId}")
    public Result<String> getMediaUrl(@PathVariable String mediaId) {
        MediaFiles mediaFile = mediaFileService.getFileById(mediaId);
        if (mediaFile == null || !StringUtils.hasText(mediaFile.getUrl())) {
            throw new BizException("视频还没有转码处理");
        }
        return Result.success(mediaFile.getUrl());
    }

}
